package com.liumuxian.user.web.controller;

import com.liumuxian.user.client.VideoClient;
import com.liumuxian.user.pojo.Problem;
import com.liumuxian.user.service.ProblemService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Calendar;
import java.util.UUID;

@RestController
@RequestMapping("/problem")
public class ProblemController {
    @Autowired
    ProblemService problemService;
    @Autowired
    VideoClient videoClient;
    @PostMapping("/add")
    public Result add(@PathVariable MultipartFile[] file){
        Result result = videoClient.uploads(file);
        return new Result(true,StatusCode.OK,"添加成功",result);
    }

    /*根据id查询
     * */
    @RequestMapping("/pronlemId")
    public String pronlemId() {
        return "";
    }

    /*删除
     *
     * */
    @RequestMapping(value = "/problemDelete/{id}")
    public Result problemDelete(@PathVariable String id) {
        problemService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }


    /*
    修改
    *
    * */
    @RequestMapping(value = "/problemUpdate")
    public Result problemUpdate(Problem problem) {
        problem.setId("1207114276746170368");
        problem.setState(0);
        problemService.saveAndFlush(problem);
        return new Result(true, StatusCode.OK, "修改成功", problem);
    }

    /*根据id查询*/
    @RequestMapping(value = "/problemseId/{id}")
    public Result problemseId(@PathVariable String id) {
        Problem p = problemService.getOne(id);
        return new Result(true, StatusCode.OK, "查询成功", p);

    }
}
